﻿<!--- Redirect empty edits --->
<cfif !isdefined("URL.cn")><cflocation url="index.cfm" /></cfif>

<cfif isdefined("FORM.dn") AND isdefined("FORM.password") AND isdefined("FORM.mboxsize")>
	<cftry>
		<cfldap server="10.100.1.9"
			username="#cgi.auth_user#" password="#form.password#"
			action="MODIFY" dn="#form.dn#"
			attributes="mDBStorageQuota=#FORM.mboxsize#;mDBOverQuotaLimit=#Round(FORM.mboxsize*1.1)#"/>
		<cfset message="User quota updated." />

		<cfcatch type="any">
			<cfset message = "Error modifying user quota:<br/>" & cfcatch.message />
		</cfcatch>
	</cftry>
</cfif>

<cfset classification = "Standard" />

<cfldap action="QUERY" name="ldapUser"
	attributes="dn,displayName,sAMAccountName,title,department,mDBStorageQuota"
	start="OU=SCFUsers,dc=SouthcentralFoundation,dc=com"
	filter="cn=#URL.cn#"
	server="10.100.1.9"
	sort="displayName"
	username="scf\Userlist"
	password="DefinedMan" />

<cfquery name="qryRosetta" datasource="RosettaStone">
	SELECT RosettaID
	FROM RosettaStone
	WHERE UserAccount = <cfqueryparam value="#ldapUser.sAMAccountName#" />
</cfquery>

<cfif qryRosetta.RecordCount gt 0>
	<cfinclude template="/code_lib/SCF_HR.cfm" />
	<cfinclude template="/code_lib/SCF_Employee.cfm" />

	<cfif SCF_HR_IsEmployeeADirector(qryRosetta.RosettaID[1])>
		<cfset classification = "Leadership" />
	<cfelseif SCF_HR_IsEmployeeASupervisor(qryRosetta.RosettaID[1])>
		<cfset classification = "Manager" />
	</cfif>
</cfif>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Mailbox Tool</title>
		<link href="/scfApps/css/scfAppsGeneral.css" rel="stylesheet" type="text/css" />
		<link href="/scfApps/css/scfApps.css" rel="stylesheet" type="text/css" />
		<link href="/scfApps/css/scfAppsBlue.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="/scfApps/scfApps.js"></script>
		<script type="text/javascript" src="/jquery/jquery-1.4.2.min.js"></script>
		<script type="text/javascript">
			/* This function copies the value from mboxtype to mboxsize - the
			 * actual form variable used to set the size. It also shows the
			 * mboxsize if a user selects "other"
			 */
			function mboxtypeChange(){
				if($('#mboxtype').val() == 'OTHER'){
					$('#mboxsize').show();
				} else {
					$('#mboxsize').hide();
					$('#mboxsize').val($('#mboxtype').val());
				}
			}

			/* This function is executed immediately (usually before even rendering, but after
			 * the DOM is constructed), and sets the value of the mboxtype, and shows
			 * mboxsize as needed.
			 */
			$(document).ready(function(){
				if($('#mboxtype option[value=\''+$('#mboxsize').val()+'\']').length){
					$('#mboxtype').val($('#mboxsize').val());
				} else {
					$('#mboxtype').val('OTHER');
					$('#mboxsize').show();
				}

				$.getJSON('usedajax.cfm?username=<cfoutput>#ldapUser.sAMAccountName#</cfoutput>', function(json){
					$('#mboxused').html(json['used'] + 'MB');
				});
			});
		</script>
		<style type="text/css">
			div#sideBarLeft div { padding: 5px; }
			input#mboxsize { display: none; }
		</style>
	</head>
	<body>
		<div id="outer">
			<div id="header">
				<h1><span class="headerColor">SCF</span> Mailbox Administration Tool</h1>
	        	<h2><cfoutput>#APPLICATION.PROGRAM_VERSION#</cfoutput></h2>
			</div>

			<div id="sideBarLeft">
				<h2>Controls</h2>
				<div>
					<a href="index.cfm">Back to Search</a>
				</div>
			</div>

			<div id="main" class="sideBarLeft">
				<cfoutput query="ldapUser">
					<cfif isdefined("message")>
						<div class="important">#message#</div><br/>
					</cfif>
					<cfform name="edit">
						<cfinput type="hidden" name="dn" value="#dn#" />
						<cfinput type="hidden" name="cn" value="#cn#" />
						<table>
							<tr>
								<td>User:</td>
								<td>#displayName#</td>
							</tr>
							<tr>
								<td>Title:</td>
								<td>#title#</td>
							</tr>
							<tr>
								<td>Department:</td>
								<td>#department#</td>
							</tr>
							<tr>
								<td>Classification:</td>
								<td>#classification#</td>
							</tr>
							<tr>
								<td>Used:</td>
								<td id="mboxused">Loading <img src="/images/loading-facebook.gif" /</td>
							<tr>
								<td>Mailbox Size:</td>
								<td>
									<select id="mboxtype" name="mboxtype" onChange="mboxtypeChange()">
										<option value="256000">Standard (250 MB)</option>
										<option value="524288">Manager (512 MB)</option>
										<option value="1048576">Director (1 GB)</option>
										<option value="20971520">Maximum (20 GB)</option>
										<option value="OTHER">Other (In kilobytes)</option>
									</select>
									<cfinput type="text" size="9" id="mboxsize" name="mboxsize" required="true" value="#ldapUser.mDBStorageQuota#" />
								</td>
							</tr>
							<tr><td>&nbsp;</td></tr>
							<tr>
								<td>
									Your password<br/>
									(needed for update)
								</td>
								<td>
									<cfinput type="password" size="24" required="true" name="password" />
								</td>
							</tr>
							<tr>
								<td>&nbsp;</td>
								<td>
									<cfinput type="submit" class="btn" name="update" value="Update" />
								</td>
							</tr>
						</table>
					</cfform>
				</cfoutput>
			</div>
		</div>
	</body>
</html>